﻿if ($.Recruit == null)
    $.Recruit = {};

$.Recruit.FileOpen = function() {
    $.manager.fileopen(16, "$.Recruit.FileOpen_Callback");
}

$.Recruit.FileOpen_Callback = function(fileurl) {
    $("input.articleFileUrl").val(fileurl);
}

$.Recruit.getList = function() {
    $.ajaxNet(
		"/manager/recruit/recruitmethod.aspx?_vb=GetList",
		{
		    PageNo: $("div.pager").pager("option", "currentPageNo"),
		    PageSize: $("div.pager").pager("option", "pageSize")
		}, function(results, context) {
    		$("table.recruitList tbody").html(results[0]);
		    $("div.pager").pager("update", results[1]);
		});
};

$.Recruit.showInputForm = function(RecruitEntity) {
    if (typeof (RecruitEntity) == "undefined") {
        $("div.inputForm")
			.find("input.RecruitNo").val("").end()
			.find("input.Name").val("").end()
			.find("input.PersonalNo").val("").end()
			.find("input.Phone").val("").end()
			.find("input.Email").val("").end()
			.find("input.PostNo").val("").end()
			.find("input.Address").val("").end()
			.find("textarea.HopeStore").val("").end()
			.find("input.JobTime").removeAttr("checked").end()
			.find("textarea.Academic").val("").end()
			.find("textarea.Career").val("").end()
			.find("textarea.License").val("").end()
			.find("input.FileURL").val("").end()
			.find("input.Status").removeAttr("checked").end()
			.find("textarea.Description").val("").end()
			.show();
    }
    else {
        $("div.inputForm")
			.find("input.RecruitNo").val(RecruitEntity.RecruitNo).end()
			.find("input.Name").val(RecruitEntity.Name).end()
			.find("input.PersonalNo").val(RecruitEntity.PersonalNo).end()
			.find("input.Phone").val(RecruitEntity.Phone).end()
			.find("input.Email").val(RecruitEntity.Email).end()
			.find("input.PostNo").val(RecruitEntity.PostNo).end()
			.find("input.Address").val(RecruitEntity.Address).end()
			.find("textarea.HopeStore").val(RecruitEntity.HopeStore).end()
			.find("input.JobTime[value=" + RecruitEntity.JobTime + "]").attr("checked", "checked").end()
			.find("textarea.Academic").val(RecruitEntity.Academic).end()
			.find("textarea.Career").val(RecruitEntity.Career).end()
			.find("textarea.License").val(RecruitEntity.License).end()
			.find("input.FileURL").val(RecruitEntity.FileURL).end()
			.find("input.Status[value=" + RecruitEntity.Status + "]").attr("checked", "checked").end()
			.find("textarea.Description").val(RecruitEntity.Description).end()
			.show();
    }
}

$.Recruit.cancelInputForm = function() {
    $("div.inputForm").hide();
}

$.Recruit.submitInputForm = function() {
    var n4RecruitNo = $("div.inputForm input.RecruitNo").val();
    var strName = $("div.inputForm input.Name").val();
    var strPersonalNo = $("div.inputForm input.PersonalNo").val();
    var strPhone = $("div.inputForm input.Phone").val();
    var strEmail = $("div.inputForm input.Email").val();
    var strPostNo = $("div.inputForm input.PostNo").val();
    var strAddress = $("div.inputForm input.Address").val();
    var strHopeStore = $("div.inputForm textarea.HopeStore").val();
    var n1JobTime = $("div.inputForm input.JobTime:checked").val();
    var strAcademic = $("div.inputForm textarea.Academic").val();
    var strCareer = $("div.inputForm textarea.Career").val();
    var strLicense = $("div.inputForm textarea.License").val();
    var strFileURL = $("div.inputForm input.FileURL").val();
    var n1Status = $("div.inputForm input.Status:checked").val();
    var strDescription = $("div.inputForm textarea.Description").val();

    if (n4RecruitNo != "") {
        $("div.inputForm").ajaxNet(
			"/manager/recruit/recruitmethod.aspx?_vb=Modify",
			{
			    "RecruitNo" : n4RecruitNo,
			    "Name" : strName,
			    "PersonalNo" : strPersonalNo,
			    "Phone" : strPhone,
			    "Email" : strEmail,
			    "PostNo" : strPostNo,
			    "Address" : strAddress,
			    "HopeStore" : strHopeStore,
			    "JobTime" : n1JobTime,
			    "Academic" : strAcademic,
			    "Career" : strCareer,
			    "License" : strLicense,
			    "FileURL" : strFileURL,
			    "Status" : n1Status,
			    "Description" : strDescription
			}, function(results, context) {
			    $("div.inputForm").hide();
			    alert('수정되었습니다.');
			    $.Recruit.getList();
			});
		return false;
    }
    else {
        $("div.inputForm").ajaxNet(
			"/manager/recruit/recruitmethod.aspx?_vb=Create",
			{
			    "Name" : strName,
			    "PersonalNo" : strPersonalNo,
			    "Phone" : strPhone,
			    "Email" : strEmail,
			    "PostNo" : strPostNo,
			    "Address" : strAddress,
			    "HopeStore" : strHopeStore,
			    "JobTime" : n1JobTime,
			    "Academic" : strAcademic,
			    "Career" : strCareer,
			    "License" : strLicense,
			    "FileURL" : strFileURL
			}, function(results, context) {
			    $("div.inputForm").hide();
			    alert('추가되었습니다.');
			    $("div.pager").pager("pageNo", 1);
			    $.Recruit.getList();
			});
    }
}

$.Recruit.modify = function(elem) {
    var RecruitEntity = $(elem).closest("tr").tagdata();

    $("table.articleList").ajaxNet(
        "/manager/recruit/recruitmethod.aspx?_vb=GetInfo",
        {
            "RecruitNo": RecruitEntity.n4RecruitNo
        }, function(results, context) {
            $.Recruit.showInputForm(JSON.parse(results));
        });
};

$.Recruit.remove = function(elem) {
    var RecruitEntity = $(elem).closest("tr").tagdata();

    $("table.articleList").ajaxNet(
		"/manager/recruit/recruitmethod.aspx?_vb=Remove",
		{
            "RecruitNo": RecruitEntity.n4RecruitNo
		}, function(results, context) {
		    alert('삭제되었습니다.');
		    $.Recruit.getList();
		});
}